package com.letou.ls.uitl;

import java.util.ArrayList;

import com.letou.ls.mode.LotteryTypeInfo;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import android.text.TextUtils;

public final class Constant {
    
    /**
     * 
     * App用dummy接口提供： 接口例 http://119.10.9.19:8080/lottery/api/account/login?username=customer01&
     * password=customer01&mac=00-01-87-af-0d
     * http://119.10.9.19:8080/lottery/api/version/getVersion?token=
     * 1FF114B7BB0478F3B61A5EDAE3B6AF0B
     * http://119.10.9.19:8080/lottery/api/lottery/getLottery?typeCode=hljklsf&
     * token=1FF114B7BB0478F3B61A5EDAE3B6AF0B
     * 
     * http://119.10.9.19:8080/lottery/api/lottery/getAbout?typeCode=hljklsfmj&
     * token=1FF114B7BB0478F3B61A5EDAE3B6AF0B
     * 
     * 03-18 21:36:04.967: V/lss(24424):
     * http://hljapi.le-tou.com.cn:45655/le-tou/api/account/login?username=lisong&password=123&mac=
     * 84:38:38:20:D8:42
     * 
     * 
     */
    // public static final String URL = "http://119.10.9.19:8080/lottery";
    // public static final String URL = "http://119.10.9.19:8080/le-tou";
    public static final String URL = "http://hljapi.le-tou.com.cn:45655";
    // 服务端API网址
    public static final String URL_SERVER_LOGIN = URL + "/api/account/login";
    public static final String URL_SERVER_VERSION = URL + "/api/version/getVersion";
    public static final String URL_SERVER_LOTTERY = URL + "/api/lottery/getLottery";
    public static final String URL_SERVER_ABOUT = URL + "/api/lottery/getAbout";
    public static String token;
    
    public static final String PRE_TAG_USERNAME = "username";
    public static final String PRE_TAG_PASSWROD = "userpassword";
    public static final String PRE_TAG_CURRENT_LTTERY_CODE = "current_lttery_code";
    
    
    public static ArrayList<LotteryTypeInfo> lotteryTypeInfo;
    public static int currentLotteryNumber;
    public static String userName;
    
    public static LotteryTypeInfo getCurrentLottery() {
        LotteryTypeInfo lottery = null;
        if (Constant.lotteryTypeInfo != null
                && Constant.lotteryTypeInfo.size() > Constant.currentLotteryNumber) {
            lottery = Constant.lotteryTypeInfo.get(Constant.currentLotteryNumber);
        }
        return lottery;
        
    }
    
    public static String getExpirationTime() {
        String time = null;
        if (Constant.lotteryTypeInfo != null
                && Constant.lotteryTypeInfo.size() > Constant.currentLotteryNumber) {
            time = Constant.lotteryTypeInfo.get(Constant.currentLotteryNumber).getExpirationTime();
        }
        if (!TextUtils.isEmpty(time)) {
            String[] array = time.split(" ");
            time = array[0];
        }
        return time;
        
    }
    
    public static String getCurrentLotteryCode() {
        if (Constant.getCurrentLottery() != null) {
            return Constant.lotteryTypeInfo.get(Constant.currentLotteryNumber).getTypeCode();
        }
        return null;
        
    }
    
    private static String currentVersion;
    
    public static String getCurrentVersion(Context context) {
        if (TextUtils.isEmpty(currentVersion)) {
            try {
                PackageInfo packInfo;
                packInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
                currentVersion = packInfo.versionName;
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return currentVersion;
    }
    
    public static String[] getCurrentVersion() {
        if (currentVersion == null) {
            return null;
        }
        
        return currentVersion.split("\\.");
    }
    
    /**
     * 黑龙江快乐十分
     */
    public static final String LOTTERY_CODE_01 = "hljklsf";
    public static final boolean isScreenSwith_01 = false;
    public static final boolean isHar_01 = false;
    /**
     * 黑龙江快乐麻将
     */
    public static final String LOTTERY_CODE_02 = "hljklmj";
    public static final boolean isScreenSwith_02 = false;
    public static final boolean isHar_02 = false;
    /**
     * 黑龙江快乐十分麻将
     */
    public static final String LOTTERY_CODE_03 = "hljklsfmj";
    public static final boolean isScreenSwith_03 = false;
    public static final boolean isHar_03 = true;
    // /**
    // * 黑龙江快乐十分麻将
    // */
    // public static final String LOTTERY_CODE_03 = "hljssc";
    /**
     * 黑龙江11选5
     */
    public static final String LOTTERY_CODE_04 = "hlj11x5";
    public static final boolean isScreenSwith_04 = true;
    public static final boolean isHar_04 = false;
    
    /**
     * 获取SD卡路径
     * 
     * @return /sdcard/
     */
    public static String getSDCardPath() {
        if (sdCardIsExit()) {
            return Environment.getExternalStorageDirectory().toString() + "/";
        }
        return null;
    }
    
    /**
     * 判断SD卡是否存在
     * 
     * @return
     */
    public static boolean sdCardIsExit() {
        return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    }
    
    /**
     * 获取文件名
     * 
     * @param filename
     * @return
     */
    public static String getName(String filename) {
        if (filename == null) {
            return null;
        }
        int index = indexOfLastSeparator(filename);
        return filename.substring(index + 1);
    }
    
    public static int indexOfLastSeparator(String filename) {
        if (filename == null) {
            return -1;
        }
        int lastUnixPos = filename.lastIndexOf('/');
        int lastWindowsPos = filename.lastIndexOf('\\');
        return Math.max(lastUnixPos, lastWindowsPos);
    }
    
}
